package com.xy.mvvmdemo

import java.lang.Exception
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.lang.reflect.Proxy

/**
 * @ClassName MHookHelp
 * @Author xy
 * @Date 2021/6/28 10:50
 * @Description 动态代理
 */
object MHookHelp:InvocationHandler {
    private var any:Any?=null

    fun newProxyInstance(any:Any):Any{
        return Proxy.newProxyInstance(any.javaClass.classLoader,any.javaClass.interfaces,this)
    }
    override fun invoke(proxy: Any?, method: Method?, args: Array<out Any>?): Any {
        var ret: Any? = null
        try {
            ret =  method?.invoke(proxy,args)!!
        }catch (e:Exception){
            e.printStackTrace()
        }

        return ret!!
    }


}